package com.lemon.core.base.pojo.tree;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 基础节点
 *
 * @author pan
 * @since 2018-08-27
 */
@Data
public class BaseNode implements INode<Long> {

    private static final long serialVersionUID = 1L;

    /**
     * 节点ID
     */
    protected Long id;

    /**
     * 父节点ID
     */
    protected Long parentId;

    /**
     * 子孙节点
     */
    protected List<INode<Long>> children = new ArrayList<>();

    /**
     * 是否有子孙节点
     */
    private Boolean hasChildren;

    /**
     * 是否有子孙节点
     */
    @Override
    public Boolean getHasChildren() {
        if (children.isEmpty()) {
            return this.hasChildren != null ? this.hasChildren : false;
        } else {
            return true;
        }
    }

}
